package com.example.myfoodrecipe.data.local

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.example.myfoodrecipe.data.local.entity.FavoriteEntity
import com.example.myfoodrecipe.data.local.entity.RecipeEntity
import com.example.myfoodrecipe.util.RecipeTypeConverter

@TypeConverters(RecipeTypeConverter::class)
@Database(entities = [RecipeEntity::class,FavoriteEntity::class],version = 1,exportSchema = false)
abstract class RecipeDatabase: RoomDatabase() {
    abstract fun getRecipeDao(): RecipeDao

    companion object{
        private var instance: RecipeDatabase? = null
        @Synchronized
        fun getDatabase(context: Context): RecipeDatabase{
            instance?.let {
                return it
            }
            return Room.databaseBuilder(context.applicationContext,
            RecipeDatabase::class.java,"foodRecipe_database")
                .build().apply {
                    instance = this
                }

        }
    }
}